package com.huaxin.hxcloud.dialog;

import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;

import com.huaxin.hxcloud.R;
import com.huaxindata.common.base.HxBaseDialogFragment;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author lwjing
 * @date 2018/7/13
 * @Desc $desc$  spt远程控制初始化 刷新等操作 的底部弹框
 * Copyright HUAXIN DATA. All rights reserved.
 */
public class SptRemoteContralDialog extends HxBaseDialogFragment implements View.OnClickListener {
    @BindView(R.id.dialog_title)
    TextView    mDialogTitle;
    @BindView(R.id.tv_divece_stata)
    TextView    mTvDiveceStata;
    @BindView(R.id.tv_ref)
    TextView    mBtRefresh;
    @BindView(R.id.bt_init)
    RadioButton mBtInit;
    @BindView(R.id.bt_open)
    RadioButton      mBtOpen;
    @BindView(R.id.bt_close)
    RadioButton      mBtClose;
    @BindView(R.id.bt_comfir)
    Button      mBtComfir;

    private int index = -1;
    private ClickLiestner liestner;

    @Override
    public void onStart() {
        super.onStart();
        WindowManager.LayoutParams params = getDialog().getWindow().getAttributes();
        params.windowAnimations=R.style.DialogBottom;
        setWidthOnHeight(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    @Override
    public int setRootViewId() {
        return R.layout.dialog_bttom_spt_init;
    }

    @Override
    public void initData() {
        Bundle arg = getArguments();
        if (arg == null){
            return;
        }
        int status = arg.getInt("status");
        refreshStata(status);

    }

    @Override
    public int showPosition() {
        return Gravity.BOTTOM;
    }

    @OnClick({R.id.tv_ref, R.id.bt_init,R.id.bt_open,R.id.bt_close,R.id.bt_comfir})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_ref:
                // 刷新 更新状态
                index = 0;
                if (liestner != null) {
                    liestner.onClick(index);
                }

                break;
            case R.id.bt_init:
                // 初始化
                index = 1;
                if (liestner != null) {
                    liestner.onClick(index);
                }
                dismiss();
                break;
            case R.id.bt_open:
                //手动
                index = 2;
                if (liestner != null) {
                    liestner.onClick(index);
                }
                dismiss();
                break;
            case R.id.bt_close:
                // 自动
                index = 3;
                if (liestner != null) {
                    liestner.onClick(index);
                }
                dismiss();
                break;
            case R.id.bt_comfir:
                dismiss();
                break;
        }
    }


    public void refreshStata(int stuta) {
        switch (stuta) {
            case -1:
                mTvDiveceStata.setText("不在线");
                break;
            case 0://手动
                mTvDiveceStata.setText("手动");
                break;
            case 1://自动
                mTvDiveceStata.setText("自动");
                break;
            case -3:
                mTvDiveceStata.setText("请初始化");
                break;
            case -2:
                mTvDiveceStata.setText("设备不存在");
                break;
            default:
                break;
        }
    }

    public void setOnclikLiestner(ClickLiestner liestner) {
        this.liestner = liestner;
    }

    public interface ClickLiestner {
        public void onClick(int index);
    }
}
